<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/9
  Time: 11:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>销售机会页面</title>
</head>
<body>
<%-- 多条件查询 --%>
<form id="form" action="${pageContext.request.contextPath}/sale/saleList" method="post">
    客户:<select name="customer_Id">
            <option value="">请选择</option>
            <option value="101" <c:if test="${params.customer_Id=='101'}">selected</c:if> >客户1</option>
            <option value="102" <c:if test="${params.customer_Id=='102'}">selected</c:if> >客户2</option>
            <option value="103" <c:if test="${params.customer_Id=='103'}">selected</c:if> >客户3</option>
        </select>
    成功率：<select name="success">
            <option value="">请选择</option>
            <option value="50" <c:if test="${params.success=='50'}">selected</c:if> >%50</option>
            <option value="60" <c:if test="${params.success=='60'}">selected</c:if> >%60</option>
            <option value="70" <c:if test="${params.success=='70'}">selected</c:if> >%70</option>
            <option value="80" <c:if test="${params.success=='80'}">selected</c:if> >%80</option>
            <option value="90" <c:if test="${params.success=='90'}">selected</c:if> >%90</option>
        </select>
    机会状态：<select name="status">
                <option value="">请选择</option>
                <option value="立项评估" <c:if test="${saleOpportunity.status=='立项评估'}">selected</c:if> >立项评估</option>
                <option value="商务谈判" <c:if test="${saleOpportunity.status=='商务谈判'}">selected</c:if> >商务谈判</option>
                <option value="解决方案" <c:if test="${saleOpportunity.status=='解决方案'}">selected</c:if> >解决方案</option>
                <option value="初期沟通" <c:if test="${saleOpportunity.status=='初期沟通'}">selected</c:if> >初期沟通</option>
                <option value="已报价" <c:if test="${saleOpportunity.status=='已报价'}">selected</c:if> >已报价</option>
                <option value="合同/订单签订" <c:if test="${saleOpportunity.status=='合同/订单签订'}">selected</c:if> >合同/订单签订</option>
            </select>

     <%--分页查询--%>
    <input type="hidden" name="pageNum" value="${saleOpportunities.pageNum}">
    <input type="hidden" name="pageSize" value="${saleOpportunities.pageSize}">
    <input type="submit" value="查询">
</form>
    <a href="${pageContext.request.contextPath}/sale/toAdd">新增</a>
    <table border="1px">
        <thead>
            <tr>
                <td>ID</td>
                <td>客户ID</td>
                <td>机会来源</td>
                <td>成功几率</td>
                <td>机会概要</td>
                <td>客户联系人ID</td>
                <td>客户联系人电话</td>
                <td>机会描述</td>
                <td>销售机会创建人</td>
                <td>销售机会创建时间</td>
                <td>被分配给的客户经理</td>
                <td>分配时间</td>
                <td>销售机会的状态</td>
                <td>是否已经被删除</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
        <c:forEach items="${saleOpportunities.list}" var="saleOpportunitie">
            <tr>
                <td>${saleOpportunitie.id}</td>
                <td>${saleOpportunitie.customer_Id}</td>
                <td>${saleOpportunitie.source}</td>
                <td>${saleOpportunitie.success}</td>
                <td>${saleOpportunitie.general}</td>
                <td>${saleOpportunitie.contact_Id}</td>
                <td>${saleOpportunitie.contact_Phone}</td>
                <td>${saleOpportunitie.description}</td>
                <td>${saleOpportunitie.creator}</td>
                <td>${saleOpportunitie.create_Date}</td>
                <td>${saleOpportunitie.manager_Id}</td>
                <td>${saleOpportunitie.allot_Date}</td>
                <td>${saleOpportunitie.status}</td>
                <td>${saleOpportunitie.delete_Status=="0"?"未删除":"已删除"}</td>
                <td>
                    <a href="javascript:deleteSale(${saleOpportunitie.id})">删除</a>
                    <a href="${pageContext.request.contextPath}/sale/toUpdate?id=${saleOpportunitie.id}">修改</a>
                </td>
            </tr>
            </c:forEach>
        </tbody>
    </table>
        <div>
            <a href="javascript:goPage(${saleOpportunities.pageNum-1})">上一页</a>
            <a href="javascript:goPage(${saleOpportunities.pageNum+1})">下一页</a>
            当前页：${saleOpportunities.pageNum},总记录数：${saleOpportunities.total},总页数：${saleOpportunities.pages}
        </div>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.min.js"></script>
<script>

    function goPage(num) {
        //跳转到对应页面
        $("input[name='pageNum']").val(num);
        //提交表单
        $("form").submit();

    }

    function deleteSale(id) {
        if(confirm("你确定要删除吗？")){ //显示一个带有指定消息和，确定及取消按钮的对话框
        //异步删除 通过jquery发送ajax请求
        $.ajax({ //代表创建异步请求对象
            url:"${pageContext.request.contextPath}/sale/delete", //向后台发送请求
            type:"get", //发送请求的方式
            data:{"id":id}, //传递对应的数据
            dataType:"json", //指定后台响应的数据类型 "json"响应回json字符串
            success:function(result){ //相当于监听响应
                //参数result 自动把后台响应的数据封装到该参数中
                alert("删除成功，返回结果为"+JSON.stringify(result)); //将json字符串转为字符串输出
                if(result.code==200){
                    alert("删除成功");
                    //重新加载页面或者跳转页面
                    window.location.reload();
                }else{
                    alert("删除失败");
                }
            },
            error:function () {
                alert("删除失败!");
            }
        });
        }
    }
</script>
</body>
</html>
